﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>工位甘特图</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        table tr td{padding:0px 5px}
    </style>
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width: 100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
        <form id="searchForm" method="post" style="margin-bottom: 0;">
            <table>
	    		<tr class="divLabel">
                    <td>分厂:</td>
                    <td>工区:</td>
                    <td>班:</td>
                    <td>排产开始日期:</td>
                    <td>排产结束日期:</td>
	    		</tr>
                <tr>
                    <td><select id="ddlFactory" class="easyui-combobox"  data-options="width:120,height:20 "></select></td>
                    <td><select id="ddlWorkcenter" class="easyui-combobox"  data-options="width:120,height:20 "></select></td>
                    <td><select id="ddlShift" class="easyui-combobox"  data-options="width:120,height:20, panelHeight:'auto' "></select></td>
                    <td><input id="txtStartDate" type="text" class="easyui-datebox" style="height: 20px;width: 148px" /></td>
                    <td><input id="txtEndDate" type="text" class="easyui-datebox" style="height: 20px;width: 148px" /></td>
                    <td>
                         <a href="javascript:void(0)" id="btnSearch" class="easyui-linkbutton" data-options="width:80" style="margin-left:10px;">查询</a>
                         <a href="javascript:void(0)" id="btnReset" class="easyui-linkbutton" data-options="width:80" style="margin-left:10px;">重置</a>
                    </td>
                </tr>
             </table>
        </form>
        </div>
    </div>
    <div class="panelSection">    
        <div class="easyui-panel " title="工位甘特图" style="padding:3px;width: 100%"data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <div id="container"></div>
        </div>
    </div>
    <div id="dg" style="display:none" ></div> 
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/zh-cn.js"></script>  
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-base.min.js"></script>        
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-ui.min.js"></script>        
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-exports.min.js"></script>        
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-gantt.min.js"></script>        
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-data-adapter.min.js"></script>
<script type="text/javascript">
var page = {
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ZSLimitedCapacityHandler.ashx",
        returnData:null,
        //初始化页面
        init: function () {
            page.bind();
           //page.loadResGrant();
        },
        //页面事件绑定
        bind: function () {
            $("#ddlFactory").combobox({
                panelHeight: 'auto',
                valueField: 'FACTORYID',
                textField: 'FACTORYNAME',
                url: page.rootPath + "/Ashx/CommonHandler.ashx" + "?action=getFactory",
                onSelect: function (record) {
                    page.loadWorkcenter(record.FACTORYID);
                }
            });

            $("#ddlWorkcenter").combobox({
                panelHeight: 'auto',
                valueField: 'WORKCENTERID',
                textField: 'WORKCENTERNAME',
                onSelect: function (record) {
                    page.loadShift(record.WORKCENTERID);
                }
            });

            $("#ddlShift").combobox({
                panelHeight: 'auto',
                valueField: 'SHIFTID',
                textField: 'SHIFTNAME'
            });
             //搜索
            $('#btnSearch').on("click", function () {  
                page.reset(false,true);
                page.loadResGrant();
            });
             //清除按钮
            $('#btnReset').on("click", function () {  
                page.reset(true,true);
            });
        },
loadWorkcenter: function (factoryId) {
            if (isNullOrWhiteSpaceStr(factoryId)) {
                return;
            }
            $("#ddlWorkcenter").combobox('clear');
            $("#ddlWorkcenter").combobox('loadData', []);
            $("#ddlShift").combobox('clear');
            $("#ddlShift").combobox('loadData', []);
            $.ajax({
                type: "Get",
                url: page.rootPath + "/Ashx/ApsHandler/ApsZsTeamShiftHandler.ashx" + "?action=GetWorkCenter&factoryId=" + factoryId,
                cashe: false,
                async: false, //同步
                dataType: "json",
                beforeSend: function () {

                },
                success: function (data) {
                    $("#ddlWorkcenter").combobox('loadData', data.DBTable);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
loadShift: function (workcenterId) {
            if (isNullOrWhiteSpaceStr(workcenterId)) {
                return;
            }
            $("#ddlShift").combobox('clear');
            $("#ddlShift").combobox('loadData',[]);
            $.ajax({
                type: "Get",
                url: page.rootPath + "/Ashx/ApsHandler/ApsZsTeamShiftHandler.ashx" + "?action=GetShift&workcenterId=" + workcenterId,
                cashe: false,
                async: false, //同步
                dataType: "json",
                beforeSend: function () {

                },
                success: function (data) {
                    console.log(data);
//                    var data=JSON.parse(data);
                    $("#ddlShift").combobox('loadData', data.DBTable)
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //清除方法，重要！！！
reset: function (iscondition, isresult) {
            clearMessage();
            if(iscondition){
                $('#searchForm').form('clear');
                $("#ddlFactory").combobox('select', ''); 
            }
            if(isresult){                
                $("#container").empty();
            }
        },        
timelineTooltip:function(_this){
            var period=_this.period;
            var numChildren = _this.item.numChildren();
            var startDate = anychart.format.dateTime(_this.start, "yyyy-MM-dd HH:mm:ss");
            var endDate = anychart.format.dateTime(_this.end, "yyyy-MM-dd HH:mm:ss");
            var parentText ="";
            var childText =""
            if(period!=null)//悬停在period上
            {
                var customData=period.customData;

                childText="<span style='font-weight:600;font-size:12pt'>" + 
                                '批次:'+customData.containername + "<br>"+
                                '工序:'+customData.workflowstepname + "<br>"+
                                '开始:'+customData.stepstarthms + "<br>"+
                                '结束:'+customData.stependhms+"</span>";
            }else{
                let periods= _this.item.get('periods');
                childText="<span style='font-weight:600;font-size:12pt'>"; 
                periods.forEach(function(_period){
                    var customData=_period.customData;
                    childText+=customData.workflowstepname.split('-')[0]+"序:"+customData.stepstarthms+" 到 "+customData.stependhms+ "<br>";
                })
                childText+="</span>";
            }
            if (numChildren > 0) {
                return parentText;
            } else {
                return childText;
            }
        },
drawingFunction:function () {
          var shapes = this["shapes"];
          var path = shapes["path"];
          var bounds = this["predictedBounds"];
          var item=this["item"];
          var h = bounds.height;
          var t = bounds.top;
          var l = bounds.left;
          var r = l + bounds.width;
          var h1 = t + h;   

        let period=this['period'];
        let customData=period.customData;

        let stepstarthms=dayjs(dayjs().format('YYYY/MM/DD')+customData.stepstarthms);
        let stependhms=dayjs(dayjs().format('YYYY/MM/DD')+customData.stependhms);

        h=h*customData.ratio;
        t=t+h*customData.startPercent;
        h1=t+h;


        path.moveTo(l, t);
        path.lineTo(l , h1 );
        path.lineTo(r, h1);
        path.lineTo(r, t);

        path.close(); 
}, 
labelTextSettingsOverrider:function(label, item) {
            var _periods=item.get('periods');               
            _periods.forEach(function(i){
            if(i.showcolor=="1")
            {
                label.fontColor('red');                    
            }

            if(i.showcolor=="2")
            {
                label.fontColor('yellow');                    
            }
            });           
        } ,
//设备甘特图加载方法
loadResGrant: function () { //有限产能加载方法
            anychart.onDocumentReady(function () {
                var param="";
                param+="&factoryID="+$("#ddlFactory").combobox('getValue');
                param+="&workcenterID="+$("#ddlWorkcenter").combobox('getValue');
                param+="&shiftID="+$("#ddlShift").combobox('getValue');
                param+="&startDate="+$("#txtStartDate").datebox('getValue');
                param+="&endDate="+$("#txtEndDate").datebox('getValue');

                anychart.data.loadJsonFile(page.ajaxUrl + "?action=GetWorkStationApsForGrant"+param, function (result) {
                    anychart.format.outputLocale('zh-cn');
                    anychart.format.inputDateTimeFormat("yyyy/MM/dd HH:mm:ss");

                    if(result.Result==false){
                        displayMessage(result.Message, false);
                        return;
                    }

                    var data=JSON.parse(result.ReturnData);
                    page.returnData=data;
                    var treeData = anychart.data.tree(data, 'as-table');
                    chart = anychart.ganttResource();
                    chart.defaultRowHeight(80);
                    chart.splitterPosition(130); //左边grid宽度
                    chart.data(treeData);
                    //设置列
                    var dataGrid = chart.dataGrid();
                    dataGrid.column(0)
                            .title('')
                            .width(30)
                            .cellTextSettings({ hAlign: 'center' });
                    dataGrid.column(1)
                            .title("工位")
                            .width(100)
                            .cellTextSettingsOverrider(page.labelTextSettingsOverrider)
                            .cellTextSettings({ hAlign: 'left', fontSize:12});
                    dataGrid.tooltip().useHtml(true); 
                    var periods = chart.getTimeline().periods();
                    periods.height(75);
                    // draw custom periods
                    periods.rendering().drawer(page.drawingFunction);

                    //图形块的label
                    var periodLabels =periods.labels();
                    periodLabels.enabled(true);
                    periodLabels.useHtml(true);
                    periodLabels.fontColor("#104d89");
                    periodLabels.fontWeight(600);
                    periodLabels.format(function() {
                        let customData=this.period.customData;
                        if(customData!=null){
                            if(customData.isHolidate!=null&&customData.isHolidate=='1'){
                                var text='<span style="color:#fff;font-wieght:bold">'+this.period.text+'</span>';
                                return text;     
                            }
                        }
                    });
            
                chart.getTimeline().tooltip().useHtml(true);
                chart.getTimeline().tooltip().format(function() {
                    return  page.timelineTooltip(this);
                });

                chart.contextMenu(false);//禁用右键
                chart.container('container');
                chart.draw();
                chart.fitAll();
                // Enable chart redrawing.
                chart.autoRedraw(true);
                chart.zoomTo("day", 31, "first-date");
//                chart.listen("rowDblClick", function (e) {
//                   if(e.period!=null){
//                            var parent=e.item.getParent();
//                            var item=e.item;
//                            //console.log(item.get('id'));
//                            var popupParam={resourceId:item.get('id'),containDate:e.period.start};

//                            var url="ApsLMResourceDetailPage.html?v=" + new Date().getTime();
//                            url += "&parentDiv=dg";
//                            $('#dg').dialog({
//                                title: '批次工序排产计划详细查看',
//                                fit: true,
//                                top: 10,
//                                closed: false,
//                                cache: false,
//                                modal: true,
//                                content: '<iframe src="' + url + '" width="100%" height="99%" frameborder="0" scrolling="auto"></iframe>',
//                                returnData:null,
//                                popupData: popupParam, //弹出页面的传参
//                                onClose: function () {
//                                    var returnData = $("#dg").dialog('options').returnData; //返回数据
//                                    if (returnData != null&&returnData.isParentRefresh) {
//                                        //console.log('更新父级数据');
//                                        $("#container").empty();
//                                        page.loadResGrant();
//                                        //displayMessage("调整成功", true);
//                                    }


//                                }
//                            });
//                        }
//                    });

                    });

                });
        }
    }

    $(function () {
        page.init(); 
    })
</script>

